# -*- coding: utf-8 -*-
"""
Created on Sat Dec 21 19:34:46 2024

@author: lenovo
"""

file_path = r"D:\Code\typhoon\2025.1.22\trmatch_cntl_tr0016"  # 替换为你的文件路径
with open(file_path, "r") as file:
    lines = file.readlines()  # 按行读取文件内容
    
    

# 得到开始行
s=[]
for i in range(len(lines)):
    if lines[i].startswith("TRACK_ID"):
        # 解析 TRACK_ID 和 START_TIME
        s.append(i)        
s.append( len(lines)-1 )



# 选取单个台风数据，得到标题，并写入
for t in range(len(s)-1):
    # 得到台风名
    i=s[t]
    nameline1 = lines[i]
    parts1 = nameline1.split()
    
    name=parts1[0]+"_"+parts1[1]
    # 
    with open(f"D:\\Code\\typhoon\\2025.1.22\\{name}" , "w") as f:
        f.writelines( lines[s[t]:s[t+1]] )  # 写入筛选后的行
        
